/**********************************************************************
  Copyright(c) 2021 Arm Corporation All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.
    * Neither the name of Arm Corporation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/
.arch armv8-a+sve

.section .bss

.align 8
gps:
.space 29*8

.align 8
simd_regs:
.space 32*32

.section .text

.global	nosimd_memcpy
.type	nosimd_memcpy,%function
.align	5
nosimd_memcpy:
	mov		x10, #0
cpy_begin:
	cmp		x10, x2
	b.ge	cpy_end
	ldrb	w9, [x1, x10]
	strb	w9, [x0, x10]
	add		x10, x10, 1
	b		cpy_begin
cpy_end:
	ret

.global	nosimd_memset
.type	nosimd_memset,%function
.align	5
nosimd_memset:
	mov		x10, #0
set_begin:
	cmp		x10, x2
	b.ge	set_end
	strb	w1, [x0, x10]
	add		x10, x10, 1
	b		set_begin
set_end:
	ret

.global	dump_gps
.type	dump_gps,%function
.align	5
dump_gps:
	str	x28,[sp,#-16]!
	ldr	x28,=gps
	stp	x0,x1,[x28]
	stp	x2,x3,[x28,#16]
	stp	x4,x5,[x28,#32]
	stp	x6,x7,[x28,#48]
	stp	x8,x9,[x28,#64]
	stp	x10,x11,[x28,#80]
	stp	x12,x13,[x28,#96]
	stp	x14,x15,[x28,#112]
	stp	x16,x17,[x28,#128]
	stp	x18,x19,[x28,#144]
	stp	x20,x21,[x28,#160]
	stp	x22,x23,[x28,#176]
	stp	x24,x25,[x28,#192]
	stp	x26,x27,[x28,#208]
	ldr	x0,[sp],#16
	str	x0,[x28,#224]
	mov	x28,x0

	ret


.global	dump_simd_regs
.type	dump_simd_regs,%function
.align	5
dump_simd_regs:
	ldr	x0,=simd_regs
	stp	q0,q1,[x0]
	stp	q2,q3,[x0,#32]
	stp	q4,q5,[x0,#64]
	stp	q6,q7,[x0,#96]
	stp	q8,q9,[x0,#128]
	stp	q10,q11,[x0,#160]
	stp	q12,q13,[x0,#192]
	stp	q14,q15,[x0,#224]
	stp	q16,q17,[x0,#256]
	stp	q18,q19,[x0,#288]
	stp	q20,q21,[x0,#320]
	stp	q22,q23,[x0,#352]
	stp	q24,q25,[x0,#384]
	stp	q26,q27,[x0,#416]
	stp	q28,q29,[x0,#448]
	stp	q30,q31,[x0,#480]

	ret

.global	dump_sve256_regs
.type	dump_sve256_regs,%function
.align	5
dump_sve256_regs:
	ldr	x0,=simd_regs
	str	z0,[x0, #0, MUL VL]
	str	z1,[x0, #1, MUL VL]
	str	z2,[x0, #2, MUL VL]
	str	z3,[x0, #3, MUL VL]
	str	z4,[x0, #4, MUL VL]
	str	z5,[x0, #5, MUL VL]
	str	z6,[x0, #6, MUL VL]
	str	z7,[x0, #7, MUL VL]
	str	z8,[x0, #8, MUL VL]
	str	z9,[x0, #9, MUL VL]
	str	z10,[x0, #10, MUL VL]
	str	z11,[x0, #11, MUL VL]
	str	z12,[x0, #12, MUL VL]
	str	z13,[x0, #13, MUL VL]
	str	z14,[x0, #14, MUL VL]
	str	z15,[x0, #15, MUL VL]
	str	z16,[x0, #16, MUL VL]
	str	z17,[x0, #17, MUL VL]
	str	z18,[x0, #18, MUL VL]
	str	z19,[x0, #19, MUL VL]
	str	z20,[x0, #20, MUL VL]
	str	z21,[x0, #21, MUL VL]
	str	z22,[x0, #22, MUL VL]
	str	z23,[x0, #23, MUL VL]
	str	z24,[x0, #24, MUL VL]
	str	z25,[x0, #25, MUL VL]
	str	z26,[x0, #26, MUL VL]
	str	z27,[x0, #27, MUL VL]
	str	z28,[x0, #28, MUL VL]
	str	z29,[x0, #29, MUL VL]
	str	z30,[x0, #30, MUL VL]
	str	z31,[x0, #31, MUL VL]

	ret

.global rdrsp
.type	rdrsp,%function
.align	5
rdrsp:
	mov	x0,sp

	ret
